package com.jboa.web.action;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.jboa.service.IBizClaimVoucherService;
import com.jboa.service.ICheckService;
import com.jboa.vo.BizCheckResult;
import com.jboa.vo.BizClaimVoucher;
import com.jboa.vo.BizLeave;
import com.jboa.vo.SysEmployee;
import com.opensymphony.xwork2.ActionContext;

public class ManagerAction {
	@Autowired
	@Qualifier("checkService")
	private ICheckService checkService;
	@Autowired
	@Qualifier("voucherService")
	private IBizClaimVoucherService voucherservice;
	private BizCheckResult checkResult;
	private BizLeave leave;

	/**
	 * 部门经理审核报销单
	 */
	public String DeptManagerCheck() {
		// 获取原报销单信息
		checkResult.setBizClaimVoucher(voucherservice.getDetailById(checkResult
				.getBizClaimVoucher().getId()));
		// 获取审核人员信息
		SysEmployee employee = (SysEmployee) ActionContext.getContext()
				.getSession().get("employee");
		checkResult.setCheckEmployee(employee);
		checkResult.setCheckTime(new Date());
		if (checkService.deptManagerCheckVoucher(checkResult)) {
			return "success";
		}
		return "input";
	}

	/**
	 * 总经理审核报销单
	 */
	public String ManagerCheck() {
		// 获取原报销单信息
		checkResult.setBizClaimVoucher(voucherservice.getDetailById(checkResult
				.getBizClaimVoucher().getId()));
		// 获取审核人员信息
		SysEmployee employee = (SysEmployee) ActionContext.getContext()
				.getSession().get("employee");
		checkResult.setCheckEmployee(employee);
		checkResult.setCheckTime(new Date());
		if (checkService.ManagerCheckVoucher(checkResult)) {
			return "success";
		}
		return "input";
	}

	/**
	 * 财务处理报销单
	 */
	public String cashierDeal() {
		// 获取原报销单信息
		checkResult.setBizClaimVoucher(voucherservice.getDetailById(checkResult
				.getBizClaimVoucher().getId()));
		// 获取处理报销单人员信息
		SysEmployee employee = (SysEmployee) ActionContext.getContext()
				.getSession().get("employee");
		checkResult.setCheckEmployee(employee);
		checkResult.setCheckTime(new Date());
		if (checkService.cashierDeal(checkResult)) {
 			return "success";
		}
		return "input";
	}
	
	
	
	/**
	 * 部门经理审批请假单
	 */
	public String deptCheckLeave(){
		leave.setStatus(leave.getStatus().substring(0,3));
		if(checkService.deptCheckLeave(leave)){
			return "success";
		}
		return "input";
	}
	
	public BizCheckResult getCheckResult() {
		return checkResult;
	}

	public void setCheckResult(BizCheckResult checkResult) {
		this.checkResult = checkResult;
	}

	public BizLeave getLeave() {
		return leave;
	}

	public void setLeave(BizLeave leave) {
		this.leave = leave;
	}

}
